package com.puff.controller.rider;

import com.puff.dto.OrdersCancelDTO;
import com.puff.dto.OrdersPageQueryDTO;
import com.puff.entity.Orders;
import com.puff.result.PageResult;
import com.puff.result.Result;
import com.puff.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("riderOrderController")
@RequestMapping("/rider/order")
@Api(tags = "骑手端-订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 根据订单状态，来显示所有的订单
     * @param status
     * @return
     */
    @GetMapping("/list/{status}/{riderId}")
    @ApiOperation("根据订单状态，来显示所有的订单")
    public Result<List<Orders>> list(@PathVariable("status") Integer status,
                                     @PathVariable("riderId") Long riderId){
        log.info("根据订单状态，来显示所有的订单：{},{}",status,riderId);
        List<Orders> list = orderService.list(status,riderId);
        return Result.success(list);
    }


    /**
     * 骑手接单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}/{riderId}")
    @ApiOperation("骑手接单")
    public Result delivery(@PathVariable("id") Long id,
                           @PathVariable("riderId") Long riderId){
        log.info("骑手接单，订单id:{},骑手id：{}",id,riderId);
        orderService.deliveryAndRiderId(id,riderId);
        return Result.success();
    }

    /**
     * 骑手完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}/{riderId}")
    @ApiOperation("骑手完成订单")
    public Result complete(@PathVariable("id") Long id,
                           @PathVariable("riderId") Long riderId){
        log.info("骑手完成订单，订单id:{},骑手id：{}",id,riderId);
        orderService.completeAndRiderId(id,riderId);
        return Result.success();
    }

    /**
     * 骑手取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("骑手取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception{
        log.info("骑手取消订单:{}",ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }
}
